from database import  db
from ..models.resource import Resource


class ResourceService(object):
    @classmethod
    def create(cls, **kwargs):
        resource = Resource(**kwargs)
        db.session.add(resource)
        db.session.commit()
        return resource

    @classmethod
    def random(cls):
        resouce_list = Resource.query.all()
        import random
        return random.choice(resouce_list)
    @classmethod
    def get_by_id(cls, id):
        return Resource.query.filter(Resource.id == id).one()
